<?php
/*
 * 广告逻辑处理处理类
 * By:Jin
 * 2017.12.21
**/
namespace app\agent\controller;

//代理广告
use app\common\model\Ad;

class Ads extends Base
{
	//展示广告
    public function ads($value='')
    {
        //分类
        $ty_list = [0=>'所有广告',1=>'在播广告',2=>'已下播广告',3=>'待播广告',4=>'待审核广告',5=>'审核未通过广告'];
        $inc_type = $this->request->param('inc_type',0);//类别键
    	//获取所有广告
        $data['ad_agents_id'] = $this->agent_manage_id;
        if($inc_type!=0){
            $data['ad_status'] = $inc_type;
        }
        $list = Ad::with('shops')->where($data)->order('ad_start_time','desc')->paginate(5,false,[
        'type'     => 'bootstrap',
        ]);
        $page = $list->render();
        $this->assign('page',$page);
        $this->assign('inc_type',$inc_type);
        $this->assign('ty_list',$ty_list);
        $this->assign('list', $list);
//        dump($list);die;
        return $this->fetch();
    }

    //下播
    public function stop()
    {
        $res = $this->request->get();
        // 1正在播放2已播出,3已审核未播,4未审核未播,5未通过审核
        switch($res['info']){
            case 1:
                $status = 2;
                break;
            case 2:
                $status = 3;
                break;
            case 3:
                $status = 5;
                break;
            default:
                $status = 2;
                break;
        }

        $output = Ad::where('ad_id',$res['id'])->update(['ad_status'=>$status]);
        if($output){
            return $this->success('修改成功！');
        }else{
            return $this->error('修改失败！');
        }
    }

    public function add_ads(){
        
        return $this->fetch();
    }
}